package _58LengthOfLastWord;

public class CSolution {

    public static void main(String[] args) {
        System.out.println("aa");
        System.out.println(lengthOfLastWord("word"));
        System.out.println(lengthOfLastWord("word "));
        System.out.println(lengthOfLastWord(" word"));
        System.out.println(lengthOfLastWord(" "));
    }
    private static int lengthOfLastWord(String s) {
        if(s == null || s.length()==0) {
            return 0;
        }
        s = s.trim();
        int i = s.lastIndexOf(" ");
        if(i==-1) {
            return s.length();
        }
        return s.substring(i+1,Math.max(i+1,s.length())).length();
    }
}
